<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <title>AUTOMOC_MOC_OPTIONS &mdash; CMake 4.1.1 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=a2c47e09" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css?v=4d06bd55" />
    
    <script src="../_static/documentation_options.js?v=e6a937a4"></script>
    <script src="../_static/doctools.js?v=9bcbadda"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    
    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="AUTOMOC_PATH_PREFIX" href="AUTOMOC_PATH_PREFIX.html" />
    <link rel="prev" title="AUTOMOC_MACRO_NAMES" href="AUTOMOC_MACRO_NAMES.html" />
 

  </head><body>
    <input id="sidebar-check" type="checkbox" />
    <label id="sidebar-overlay" for="sidebar-check"></label>



    <div class="related relbar1" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="AUTOMOC_PATH_PREFIX.html" title="AUTOMOC_PATH_PREFIX"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="AUTOMOC_MACRO_NAMES.html" title="AUTOMOC_MACRO_NAMES"
             accesskey="P">previous</a> |</li>
  <li>
    <label class="sidebar-toggle" for="sidebar-check"></label>
  </li>
  <li class="rootlink">
    <img src="../_static/cmake-logo-16.png" width="16" height="16" alt=""/>
    <a href="https://cmake.org/">CMake 4.1.1</a>
    <span class="reldelim1"> &#187;</span>
  </li>
  <li>
    <a href="../index.html">Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" accesskey="U">cmake-properties(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">AUTOMOC_MOC_OPTIONS</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="automoc-moc-options">
<span id="prop_tgt:AUTOMOC_MOC_OPTIONS"></span><h1>AUTOMOC_MOC_OPTIONS<a class="headerlink" href="#automoc-moc-options" title="Link to this heading">¶</a></h1>
<p>Additional options for <code class="docutils literal notranslate"><span class="pre">moc</span></code> when using <span class="target" id="index-0-prop_tgt:AUTOMOC"></span><a class="reference internal" href="AUTOMOC.html#prop_tgt:AUTOMOC" title="AUTOMOC"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">AUTOMOC</span></code></a></p>
<p>This property is only used if the <span class="target" id="index-1-prop_tgt:AUTOMOC"></span><a class="reference internal" href="AUTOMOC.html#prop_tgt:AUTOMOC" title="AUTOMOC"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">AUTOMOC</span></code></a> property is <code class="docutils literal notranslate"><span class="pre">ON</span></code>
for this target.  In this case, it holds additional command line
options which will be used when <code class="docutils literal notranslate"><span class="pre">moc</span></code> is executed during the build, i.e.
it is equivalent to the optional <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> argument of the
<span class="target" id="index-0-module:FindQt4"></span><a class="reference internal" href="../module/FindQt4.html#module:FindQt4" title="FindQt4"><code class="xref cmake cmake-module docutils literal notranslate"><span class="pre">qt4_wrap_cpp()</span></code></a> macro.</p>
<p>This property is initialized by the value of the
<span class="target" id="index-0-variable:CMAKE_AUTOMOC_MOC_OPTIONS"></span><a class="reference internal" href="../variable/CMAKE_AUTOMOC_MOC_OPTIONS.html#variable:CMAKE_AUTOMOC_MOC_OPTIONS" title="CMAKE_AUTOMOC_MOC_OPTIONS"><code class="xref cmake cmake-variable docutils literal notranslate"><span class="pre">CMAKE_AUTOMOC_MOC_OPTIONS</span></code></a> variable if it is set when a target
is created, or an empty string otherwise.</p>
<p>See the <span class="target" id="index-0-manual:cmake-qt(7)"></span><a class="reference internal" href="../manual/cmake-qt.7.html#manual:cmake-qt(7)" title="cmake-qt(7)"><code class="xref cmake cmake-manual docutils literal notranslate"><span class="pre">cmake-qt(7)</span></code></a> manual for more information on using CMake
with Qt.</p>
<section id="example">
<h2>EXAMPLE<a class="headerlink" href="#example" title="Link to this heading">¶</a></h2>
<p>In this example, the <code class="docutils literal notranslate"><span class="pre">moc</span></code> tool is invoked with the <code class="docutils literal notranslate"><span class="pre">-D_EXTRA_DEFINE</span></code>
option when generating the moc file for <code class="docutils literal notranslate"><span class="pre">object.cpp</span></code>.</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">CMakeLists.txt</span></code></dt><dd><div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">add_executable(</span><span class="nb">mocOptions</span><span class="w"> </span><span class="nb">object.cpp</span><span class="w"> </span><span class="nb">main.cpp</span><span class="nf">)</span>
<span class="nf">set_property(</span><span class="no">TARGET</span><span class="w"> </span><span class="nb">mocOptions</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">AUTOMOC</span><span class="w"> </span><span class="no">ON</span><span class="nf">)</span>
<span class="nf">target_compile_options(</span><span class="nb">mocOptions</span><span class="w"> </span><span class="no">PRIVATE</span><span class="w"> </span><span class="s">&quot;-D_EXTRA_DEFINE&quot;</span><span class="nf">)</span>
<span class="nf">set_property(</span><span class="no">TARGET</span><span class="w"> </span><span class="nb">mocOptions</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">AUTOMOC_MOC_OPTIONS</span><span class="w"> </span><span class="s">&quot;-D_EXTRA_DEFINE&quot;</span><span class="nf">)</span>
<span class="nf">target_link_libraries(</span><span class="nb">mocOptions</span><span class="w"> </span><span class="nb">Qt6</span><span class="o">::</span><span class="nb">Core</span><span class="nf">)</span>
</pre></div>
</div>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">object.hpp</span></code></dt><dd><div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="cp">#ifndef Object_HPP</span>
<span class="cp">#define Object_HPP</span>

<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;QObject&gt;</span>

<span class="cp">#ifdef _EXTRA_DEFINE</span>
<span class="k">class</span><span class="w"> </span><span class="nc">Object</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">QObject</span>
<span class="p">{</span>
<span class="n">Q_OBJECT</span>
<span class="k">public</span><span class="o">:</span>

<span class="w">  </span><span class="n">Object</span><span class="p">();</span>

<span class="p">};</span>
<span class="cp">#endif</span>

<span class="cp">#endif</span>
</pre></div>
</div>
</dd>
</dl>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
  <div>
    <h3>Table of Contents</h3>
    <ul>
<li><a class="reference internal" href="#">AUTOMOC_MOC_OPTIONS</a><ul>
<li><a class="reference internal" href="#example">EXAMPLE</a></li>
</ul>
</li>
</ul>

  </div>
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="AUTOMOC_MACRO_NAMES.html"
                          title="previous chapter">AUTOMOC_MACRO_NAMES</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="AUTOMOC_PATH_PREFIX.html"
                          title="next chapter">AUTOMOC_PATH_PREFIX</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/prop_tgt/AUTOMOC_MOC_OPTIONS.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="AUTOMOC_PATH_PREFIX.html" title="AUTOMOC_PATH_PREFIX"
             >next</a> |</li>
        <li class="right" >
          <a href="AUTOMOC_MACRO_NAMES.html" title="AUTOMOC_MACRO_NAMES"
             >previous</a> |</li>
  <li>
    <label class="sidebar-toggle" for="sidebar-check"></label>
  </li>
  <li class="rootlink">
    <img src="../_static/cmake-logo-16.png" width="16" height="16" alt=""/>
    <a href="https://cmake.org/">CMake 4.1.1</a>
    <span class="reldelim1"> &#187;</span>
  </li>
  <li>
    <a href="../index.html">Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" >cmake-properties(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">AUTOMOC_MOC_OPTIONS</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
    &#169; Copyright 2000-2025 Kitware, Inc. and Contributors.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
    </div>
<script type="text/javascript">
(function() {
  "use strict";
  const hide = () => document.getElementById("sidebar-check").checked = false;
  addEventListener("keydown", e => (e.key === "Escape") && hide());
  addEventListener("click", e => (e.target.tagName === "A") && hide());
  addEventListener("hashchange", hide)
})();
</script>
  </body>
</html>